<template>
  <div class="box3" ref="map">地图</div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

import chinaJSON from './china.json'

let map = ref()

//注册地图
echarts.registerMap('china', chinaJSON as any)
onMounted(() => {
  let mycharts = echarts.init(map.value)
  //设置配置项
  mycharts.setOption({
    //地图组件
    geo: {
      map: 'china',
      //鼠标缩放功能
      roam: true,
      left: 50,
      right: 50,
      top: 100,
      bottom: 0,
      //地图上的文字设置
      label: {
        show: true,
        color: 'white',
        fontSize: 14,
        //文字旋转
        // rotate:20
      },
      //每一个多边形样式
      itemStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: 'skyblue', // 0% 处的颜色
            },
            {
              offset: 1,
              color: 'pink', // 100% 处的颜色
            },
          ],
          global: false, // 缺省为 false
        },
        opacity: 0.5,
      },
      //地图高亮显示
      emphasis: {
        itemStyle: {
          color: 'red',
        },
        label: {
          fontSize: 40,
        },
      },
    },
    grid: {},
    series: [
      {
        type: 'lines',
        //航线系列
        data: [
          {
            coords: [
              [116.405285, 39.904989],
              [123.429096, 41.796767],
            ],
            lineStyle: {
              color: 'pink',
              width: 5,
            },
            //是否显示特效
          },
          {
            coords: [
              [116.405285, 39.904989],
              [125.3245, 43.886841],
            ],
            lineStyle: {
              color: 'pink',
              width: 5,
            },
            //是否显示特效
          },
        ],
        effect: {
          show: true,
          symbol: 'arrow',
          color: 'black',
          symbolSize: 10,
        },
      },
    ],
  })
})
</script>

<style scoped lang="scss"></style>
